package com.googlecode.jascii.printing;

import java.awt.Font;
import java.io.File;
import java.io.InputStream;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class FontUtils {

	private static String[] names = { "fireflysung.ttf" };

	  private static Map cache = new ConcurrentHashMap (names.length);
	  static {
	    for (int i=0;i<names.length ; i++) {
	    	 String name  =  names[i];
	         cache.put(name, getFont(name));
	    }
	  }

	  public static Font getFont(String name) {
	    Font font = null;
	    if (cache != null) {
	      if ((font = (Font)cache.get(name)) != null) {
	        return font;
	      }
	    }
	    String fName = "fonts"+ File.separator + name;
//	    System.out.println("Test Font::"+fName);
	    try {
	      InputStream is =   FontUtils.class.getClassLoader().getResourceAsStream(fName);
	      font = Font.createFont(Font.TRUETYPE_FONT, is);
	    } catch (Exception ex) {
	      ex.printStackTrace();
	      System.err.println(fName + " not loaded.  Using serif font.");
	      font = new Font("serif", Font.TRUETYPE_FONT, 12);
	    }
	    return font;
	  }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
